from operator import add
from itertools import groupby
from functools import reduce

data = [
    [121.1, 0.02, 0.02],
    [121.1, 0.05, 0.05],
    [122.1, 0.56, 0.6],
    [122.1, 3.79, 4.04],
    [123.1, 93.75, 100.0],
    [123.1, 0.01, 0.01],
    [124.1, 0.01, 0.01],
    [124.1, 1.01, 1.08],
    [124.1, 0.11, 0.11],
    [124.1, 0.05, 0.06],
    [125.1, 0.39, 0.41],
]


# def g(d):
#     k = d[0][:]
#     for l in d[1:]:
#         if l[0] != k[0]:
#             yield k
#             k = l
#         else:
#             k[1:] = map(add, l[1:], k[1:])
#     yield k
#
#
# print list(g(data))


print [reduce(lambda x,y: [k, x[1]+y[1], x[2]+y[2]], rows) for k, rows in groupby(data, lambda x: x[0])]


# def reduce_callback(d, i):
#     key = i[0]
#     try:
#         d[key] = list(map(add, d[key], i[1:]))
#     except KeyError:
#         d[key] = i[1:]
#     return d
#
#
# result = reduce(reduce_callback, data, {})
# result_list = [[k]+v for k,v in result.items()]
# print(result_list)
